﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using SourceStack.Entities;
using SourceStack.Repositories;

namespace SourceStack.Pages
{
   // [IgnoreAntiforgeryToken]
    public class IndexModel : PageModel
    {
       
        private MessageRepository messageRepository;
        public IndexModel()
        {
            messageRepository = new MessageRepository();
        }
        [BindProperty]
        public IList<Message> Messages { get; set; }
        //private readonly ILogger<IndexModel> _logger;

        //public IndexModel(ILogger<IndexModel> logger)
        //{
        //    _logger = logger;
        //}
        public void OnGet()
        {
            Messages = messageRepository.GetMine();
        }


        public void OnPost()
        {
            foreach (var item in Messages)
            {
                if (item.Selected)
                {
                    messageRepository.Find(item.Id).Read();
                    item.Read();
                }

            }
        }
    }

}
